<include file="public@header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:url('Order/index')}">订单管理</a></li>
		</ul>

        <form class="well form-inline margin-top-20" method="post" action="{:url('Order/index')}">
        	订单号：
            <input type="text" class="form-control" name="order_no" style="width: 250px;" value="" placeholder="请输入订单号">
			订单状态：
			<select class="form-control" name="order_status" style="width: 200px;">
				<option value="">请选择</option>
				<?php foreach($status as $k => $v) {  ?>
				<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
				<?php } ?>
			</select>
			<a class="btn btn-danger" href="{:url('Order/index')}" style="margin-left: 100px;">清空</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="submit" class="btn btn-primary" value="搜索"  />
            
        </form>
         <div class="linetotal-txt">共有{$total}条记录</div>
		<table class="table table-hover table-bordered">
			<thead>
				<tr>
					<th width="280px;">订单号</th>
					<th width="80px;">数量</th>
					<th width="130px;">总金额</th>
					<th width="180px;">用户姓名</th>
					<!-- <th width="200px;">物流单号</th> -->
					<th width="180px;">下单时间</th>
					<th width="120px;">订单状态</th>
					<th width="180">操作</th>
				</tr>
			</thead>
			<tbody>
	            <foreach name="data" item="v">
	            <tr>
	            	<td>{$v.order_no}</td>
	            	<td>{$v.number}</td>
	            	<td>{$v.order_money}</td>
	            	<td>{$v.user_name}</td>
	            	<!-- <td></td> -->
	            	<td>{$v.create_time}</td>
	            	<td><?php echo $status[$v['order_status']];  ?></td>
	            	<td>
	            		<if condition="$v['order_status'] eq 1">
	            		<a class="btn btn-xs btn-primary btn-warning " href="shipments?order_id={$v.order_id}">发货</a>
	            		</if>
	            		<if condition="$v['order_status'] eq 2">
	            		<a class="btn btn-xs btn-primary btn-warning " href='lookLogistics?order_id={$v.order_id}&type=1'>查看物流</a>
	            		</if>
	            		<if condition="$v['order_status'] eq 8">
	            		<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:replace({$v.order_id},1);">同意换货</span>&nbsp;&nbsp;
	            		|&nbsp;&nbsp;&nbsp;<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:replace({$v.order_id},2);">拒绝换货</span>
	            		</if>
	            		<if condition="$v['order_status'] eq 7">
	            		<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:exchange({$v.order_id},1);">同意退货</span>&nbsp;&nbsp;
	            		|&nbsp;&nbsp;&nbsp;<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:exchange({$v.order_id},2);">拒绝退货</span>
	            		</if>
	            		<if condition="$v['order_status'] eq 9">
	            		<a class="btn btn-xs btn-primary btn-warning" href='lookLogistics?order_id={$v.order_id}&type=2'>查看物流</a>&nbsp;&nbsp;
	            		|&nbsp;&nbsp;&nbsp;<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:receive({$v.order_id},1);">确认收货</span>
	            		</if>
	            		<if condition="$v['order_status'] eq 10">
	            		<a class="btn btn-xs btn-primary btn-warning " href='lookLogistics?order_id={$v.order_id}&type=2'>查看物流</a>&nbsp;&nbsp;
	            		|&nbsp;&nbsp;&nbsp;<span class="btn btn-xs btn-primary btn-warning" onClick="javascript:receive({$v.order_id},2);">确认收货</span>
	            		</if>
	            	</td>
	            </tr>
	            </foreach>
			</tbody>
		</table>
		<div class="pagination">{$page}</div>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		function exchange(order_id,type){
			del_ok = is_del(type);
      		if(del_ok){
				$.ajax({
		            type: "POST",
		            url: "exchange",
		            data: {"order_id":order_id,'type':type},
		            dataType: "json",
		            success: function(data){
		                if(data.code ==1 ){
		                   alert(data.msg);
		                   window.location.href="/admin/order/index"
		                   return
		                }else{
		                    alert(data.msg);
		                }
		            }        
		        });
			}
		}


		function is_del(type) {
			if(type == 1){
				var msg = "你确定退货吗？";
			}else if(type == 2){
                var msg = '你确定拒绝吗？';
			}else if(type == 3){
				var msg = '是否确定收货？'+'\n'+'确认收货后自动打款至对方账户';
			}else{
				var msg = '你确定同意换货吗？';
			}
	        if (confirm(msg) == true) {
	            return true;
	        } else {
	            return false;
	        }
	    }


	    function receive(order_id,type){
	    	del_ok = is_del(3);
      		if(del_ok){
				$.ajax({
		            type: "POST",
		            url: "exchangeReceive",
		            data: {"order_id":order_id,'type':type},
		            dataType: "json",
		            success: function(data){
		                if(data.code ==1 ){
		                   alert(data.msg);
		                   window.location.href="/admin/order/index"
		                   return
		                }else{
		                    alert(data.msg);
		                }
		            }        
		        });
			}
	    }


	    function replace(order_id,type){
	    	if(type == 1){
	    		var status = 4;
	    	}else{
	    		var status = 2;
	    	}
	    	del_ok = is_del(status);
      		if(del_ok){
				$.ajax({
		            type: "POST",
		            url: "replace",
		            data: {"order_id":order_id,'type':type},
		            dataType: "json",
		            success: function(data){
		                if(data.code ==1 ){
		                   alert(data.msg);
		                   window.location.href="/admin/order/index"
		                   return
		                }else{
		                    alert(data.msg);
		                }
		            }        
		        });
			}
	    }
	</script>
</body>
</html>